package com.yx.myapplication;



import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collections;


import android.media.AudioManager;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.yx.IYxGpioListener;
import android.telephony.TelephonyManager;
import android.text.format.Time;
import android.util.Log;
import android.view.Menu;
import android.view.Surface;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.os.yx.YxWiegand;
import android.os.yx.YxDeviceManager;
public class YxDemoActivity extends Activity  implements OnClickListener {



    private Button mBtnReboot;
    private ToggleButton  mBtnBl;
    private ToggleButton  mBtnWifi;
    private Button  mBtnNav;
    private Button  mBtnFac;
    private ToggleButton mBtnHdmi;
    private String TAG="fan";

    private Button mBtTimeSet;
    private Button mBtRotate;
    private Button mBtTimezone;
    private Button mBtScreenShot;
    private Button mBtShutdown;
    private Button mBtPowerOn;

    private Button mBtPowerOnCC;
    private Button mBtSetup;
    private Button yx_reset4g;

    private Button lock;

    private Button yx_onoff,yx_time_set,yx_shutdown,yx_reboot,yx_show_bar,yx_hide_bar;
    private Button yx_fac_reset,yx_screen_shot;
    private ToggleButton yx_bl;

    private ToggleButton fan,light,led_r,led_g,led_b,led_ir,bt_relay;
    private TextView read_wiggand,write_wiggand,mdis_IP;

    private ToggleButton yx_io1out,yx_io2out,yx_io3out,yx_io4out,yx_io5out,yx_io6out,yx_io7out,yx_io8out,yx_io9out;

    private Button yx_io1in,yx_io2in,yx_io3in,yx_io4in,yx_io5in,yx_io6in,yx_io7in,yx_io8in,yx_pm,stop_ril,start_ril,mipadress;


    private Button vol,brightness,ota;

    private Button enht_reboot,enht_sleep,enht_wakeup,wdt;

    private int BROARDCAST_REBOOT=1234;
    private int BROARDCAST_SHUTDOWN=1235;
    private int BROARDCAST_HDMI_SWITCH=1236;
    private int BROARDCAST_BL_SWITCH=1237;
    private int BROARDCAST_SCREEN_SHOT=1238;
    private int BROARDCAST_NAV_SWITCH=1239;
    private int BROARDCAST_WIFI_SWITCH=1240;
    private int BROARDCAST_FAC_RESET=1241;
    private int BROARDCAST_SET_ORI=1242;
    private int BROARDCAST_SET_TIME=1243;
    private int BROARDCAST_SET_TIMEZONE=1244;
    private int BROARDCAST_POWER_TIME=1247;
    private int BROARDCAST_POWER_ON_CANCEL=1248;
    private int BROARDCAST_SETUP=1245;


    private int lock_cnt;

    private TextView textView1;
    YxWiegand yxWiegand;
    YxDeviceManager manager ;
    IYxGpioListener mygpio1,mygpio2,mygpio3,mygpio4;
    public static String bytes2hex03(byte[] bytes)
    {
        final String HEX = "0123456789abcdef";
        StringBuilder sb = new StringBuilder(bytes.length * 2);
        for (byte b : bytes)
        {
            // 取出这个字节的高4位，然后与0x0f与运算，得到一个0-15之间的数据，通过HEX.charAt(0-15)即为16进制数
            sb.append(HEX.charAt((b >> 4) & 0x0f));
            // 取出这个字节的低位，与0x0f与运算，得到一个0-15之间的数据，通过HEX.charAt(0-15)即为16进制数
            sb.append(HEX.charAt(b & 0x0f));
        }

        return sb.toString();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);




        String ver=android.os.Build.DISPLAY;
        manager =YxDeviceManager.getInstance(this);
        Log.d("liz","ver==="+ver+"oo-="+ver.indexOf("20190628.1433"));


        int angle = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
        Log.d("liz","angle==="+angle);

        mBtnReboot = (Button) findViewById(R.id.reboot);
        mBtnReboot.setOnClickListener(this);

        mBtnBl = (ToggleButton ) findViewById(R.id.bl);
        mBtnBl.setOnClickListener(this);

        mBtnWifi = (ToggleButton) findViewById(R.id.wifi);
        mBtnWifi.setOnClickListener(this);

        mBtnNav = (Button) findViewById(R.id.nav);
        mBtnNav.setOnClickListener(this);

        mBtnHdmi = (ToggleButton) findViewById(R.id.hdmi);
        mBtnHdmi.setOnClickListener(this);


        mBtnFac = (Button) findViewById(R.id.fac);
        mBtnFac.setOnClickListener(this);
        // mBtTimeSet time_set

        mBtTimeSet = (Button) findViewById(R.id.time_set);
        mBtTimeSet.setOnClickListener(this);

        mBtRotate=(Button) findViewById(R.id.rotate);
        mBtRotate.setOnClickListener(this);

        mBtTimezone=(Button) findViewById(R.id.timezone_set);
        mBtTimezone.setOnClickListener(this);
        // mBtScreenShot

        mBtScreenShot=(Button) findViewById(R.id.ScreenShot);
        mBtScreenShot.setOnClickListener(this);



        mBtShutdown=(Button) findViewById(R.id.shutdown);
        mBtShutdown.setOnClickListener(this);

        mBtPowerOn=(Button) findViewById(R.id.PowerOn);
        mBtPowerOn.setOnClickListener(this);

        mBtPowerOnCC=(Button) findViewById(R.id.PowerOnCC);
        mBtPowerOnCC.setOnClickListener(this);


        mBtSetup=(Button) findViewById(R.id.Setup);
        mBtSetup.setOnClickListener(this);


        yx_onoff=(Button) findViewById(R.id.yx_onoff);
        yx_onoff.setOnClickListener(this);

        yx_time_set=(Button) findViewById(R.id.yx_time_set);
        yx_time_set.setOnClickListener(this);

        yx_shutdown=(Button) findViewById(R.id.yx_shutdown);
        yx_shutdown.setOnClickListener(this);

        yx_reboot=(Button) findViewById(R.id.yx_reboot);
        yx_reboot.setOnClickListener(this);

        yx_show_bar=(Button) findViewById(R.id.yx_show_bar);
        yx_show_bar.setOnClickListener(this);

        yx_hide_bar=(Button) findViewById(R.id.yx_hide_bar);
        yx_hide_bar.setOnClickListener(this);


        yx_fac_reset=(Button) findViewById(R.id.yx_fac_reset);
        yx_fac_reset.setOnClickListener(this);

        yx_screen_shot=(Button) findViewById(R.id.yx_screen_shot);
        yx_screen_shot.setOnClickListener(this);


        yx_reset4g=(Button) findViewById(R.id.yx_reset4g);
        yx_reset4g.setOnClickListener(this);



        yx_bl = (ToggleButton ) findViewById(R.id.yx_bl);
        yx_bl.setOnClickListener(this);


        yx_io1out = (ToggleButton) findViewById(R.id.yx_io1out);
        yx_io1out.setOnClickListener(this);

        yx_io2out = (ToggleButton) findViewById(R.id.yx_io2out);
        yx_io2out.setOnClickListener(this);

        yx_io3out = (ToggleButton) findViewById(R.id.yx_io3out);
        yx_io3out.setOnClickListener(this);

        yx_io4out = (ToggleButton) findViewById(R.id.yx_io4out);
        yx_io4out.setOnClickListener(this);

        yx_io5out = (ToggleButton) findViewById(R.id.yx_io5out);
        yx_io5out.setOnClickListener(this);

        yx_io6out = (ToggleButton) findViewById(R.id.yx_io6out);
        yx_io6out.setOnClickListener(this);

        yx_io7out = (ToggleButton) findViewById(R.id.yx_io7out);
        yx_io7out.setOnClickListener(this);

        yx_io8out = (ToggleButton) findViewById(R.id.yx_io8out);
        yx_io8out.setOnClickListener(this);


        yx_io9out = (ToggleButton) findViewById(R.id.yx_io9out);
        yx_io9out.setOnClickListener(this);

        yx_io1in=(Button) findViewById(R.id.yx_io1in);
        yx_io1in.setOnClickListener(this);

        yx_io2in=(Button) findViewById(R.id.yx_io2in);
        yx_io2in.setOnClickListener(this);

        yx_io3in=(Button) findViewById(R.id.yx_io3in);
        yx_io3in.setOnClickListener(this);

        yx_io4in=(Button) findViewById(R.id.yx_io4in);
        yx_io4in.setOnClickListener(this);

        yx_io5in=(Button) findViewById(R.id.yx_io5in);
        yx_io5in.setOnClickListener(this);


        yx_io6in=(Button) findViewById(R.id.yx_io6in);
        yx_io6in.setOnClickListener(this);


        yx_io7in=(Button) findViewById(R.id.yx_io7in);
        yx_io7in.setOnClickListener(this);


        yx_io8in=(Button) findViewById(R.id.yx_io8in);
        yx_io8in.setOnClickListener(this);


        yx_pm=(Button) findViewById(R.id.yx_pm);
        yx_pm.setOnClickListener(this);

        stop_ril=(Button) findViewById(R.id.stop_ril);
        stop_ril.setOnClickListener(this);

        start_ril=(Button) findViewById(R.id.start_ril);
        start_ril.setOnClickListener(this);


        vol=(Button) findViewById(R.id.vol);
        vol.setOnClickListener(this);


        brightness=(Button) findViewById(R.id.brightness);
        brightness.setOnClickListener(this);

        lock=(Button) findViewById(R.id.lock);
        lock.setOnClickListener(this);

        enht_reboot=(Button) findViewById(R.id.enht_reboot);
        enht_reboot.setOnClickListener(this);

        enht_wakeup=(Button) findViewById(R.id.enht_wakeup);
        enht_wakeup.setOnClickListener(this);

        enht_sleep=(Button) findViewById(R.id.enht_sleep);
        enht_sleep.setOnClickListener(this);

        wdt=(Button) findViewById(R.id.wdt);
        wdt.setOnClickListener(this);

        mipadress=(Button) findViewById(R.id.ipadress);
        mipadress.setOnClickListener(this);


        ota=(Button) findViewById(R.id.ota);
        ota.setOnClickListener(this);


        fan = (ToggleButton ) findViewById(R.id.fan);
        fan.setOnClickListener(this);


        light = (ToggleButton ) findViewById(R.id.light);
        light.setOnClickListener(this);
        led_r = (ToggleButton ) findViewById(R.id.ledr);
        led_r.setOnClickListener(this);
        led_g = (ToggleButton ) findViewById(R.id.ledg);
        led_g.setOnClickListener(this);
        led_b = (ToggleButton ) findViewById(R.id.ledb);
        led_b.setOnClickListener(this);
        led_ir = (ToggleButton ) findViewById(R.id.ledir);
        led_ir.setOnClickListener(this);
        bt_relay = (ToggleButton ) findViewById(R.id.relay);
        bt_relay.setOnClickListener(this);

        read_wiggand = (TextView ) findViewById(R.id.readwgdata);
        write_wiggand = (TextView ) findViewById(R.id.writewgdata);
        mdis_IP =(TextView )findViewById(R.id.dis_IP);
        yxWiegand = YxWiegand.getInstance(this);
        yxWiegand.startReading(new YxWiegand.YxWiegandCallBack() {
            @Override
            public void onNewValue(byte[] bytes) {
                String str =  bytes2hex03 (bytes);
                read_wiggand.setText(str);
                Log.i("wiegand","card data is"+str);
            }
        });
     /*   mygpio1 = new IYxGpioListener.Stub() {
            @Override
            public void onNewValue(int i) throws RemoteException {
                Log.i("fan","gpio1 value is "+i);
                if(i==1){
                    yx_io1in.setText("1in H");}
                else {
                    yx_io1in.setText("1in L");
                }
            }
        };
        if(mygpio1!=null) {
            manager.register(mygpio1, 1);
        }
         mygpio2 = new IYxGpioListener.Stub() {
            @Override
            public void onNewValue(int i) throws RemoteException {
                Log.i("fan","gpio2 value is "+i);
                if(i==1){
                    yx_io2in.setText("2in H");}
                else {
                    yx_io2in.setText("2in L");
                }
            }
        };
        if(mygpio2!=null) {
            manager.register(mygpio2, 2);
        }
         mygpio3 = new IYxGpioListener.Stub() {
            @Override
            public void onNewValue(int i) throws RemoteException {
                Log.i("fan","gpio3 value is "+i);
                if(i==1){
                    yx_io3in.setText("3in H");}
                else {
                    yx_io3in.setText("3in L");
                }
            }
        };
        if(mygpio3!=null) {
            manager.register(mygpio3, 3);
        }
         mygpio4 = new IYxGpioListener.Stub() {
            @Override
            public void onNewValue(int i) throws RemoteException {
                Log.i("fan","gpio4 value is "+i);
                if(i==1){
                    yx_io4in.setText("4in H");}
                else {
                    yx_io4in.setText("4in L");
                }
            }
        };
        if(mygpio4!=null) {
            manager.register(mygpio4, 4);
        }*/
        TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
        String szImei = TelephonyMgr.getDeviceId();


        String   model= android.os.Build.MODEL;

        //获取序列号
        String serial = android.os.Build.SERIAL;
        Log.d("liz","serial==="+serial);

        Log.d("liz","model"+model);

        Log.d("liz","imei"+szImei);

        Log.d("liz","Build.DISPLAY"+android.os.Build.DISPLAY);


        Log.d("liz","Build.PRODUCT"+android.os.Build.PRODUCT);



        Log.d("12345","isApkInDebug===="+isApkInDebug(this));



        IntentFilter filter = new IntentFilter();
        filter.addAction("MyReceiver_key");
        filter.addAction("rk.android.screenshot.ok");
        this.registerReceiver(boot2, filter);


        String macAddress = null;
        WifiManager wifiMgr = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = (null == wifiMgr ? null : wifiMgr.getConnectionInfo());
        if (null != info) {
            macAddress = info.getMacAddress();
            // ip = int2ip(info.getIpAddress());
        }
        System.out.println("mac:" + macAddress);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }



    public void send_wifi(){
        Log.d(TAG,"send_wifi");

        Intent intent=new Intent();
        intent.setAction("android.intent.action.sendkey");
        intent.putExtra("keycode",1240);
        if(mBtnWifi.isChecked())intent.putExtra("wifistate",1);/*关闭WIFI*/
        else intent.putExtra("wifistate",0);/*打开WIFI*/
        this.sendBroadcast(intent);
    }
    static int navbar =0;
    public void send_nav(){

        Log.d(TAG,"send_nav");

        Intent intent=new Intent();
        // intent.setAction("android.yide.intent.action.showbar");
        intent.setAction("com.outform.unhidebar");
        // intent.setAction("android.intent.action.showbar");
        // intent.putExtra("keycode",BROARDCAST_NAV_SWITCH);
        this.sendBroadcast(intent);
        if(navbar==1) {
            navbar=0;
            manager.setNavBarNew(false);
        }
        else{
            navbar=1;
            manager.setNavBarNew(true);

        }
    }
    public void send_hdmi(){
        Log.d(TAG,"send_hdmi"+mBtnHdmi.isChecked());



        Intent intent=new Intent();
        // intent.setAction("android.yide.intent.action.hidebar");
        intent.setAction("com.outform.hidebar");
        // intent.setAction("android.intent.action.hidebar");
        // intent.putExtra("keycode",BROARDCAST_NAV_SWITCH);
        this.sendBroadcast(intent);
    }
    public void send_reboot(){
        Log.d(TAG,"send_reboot");


        // exe_su_cmd("/system/bin/reboot");

	 /*  get_temp();
	   get_hum();
	   get_proximity();
	   set_beep("beep");*/

        //   int t=ping_test("www.baidu.com");


        //   Log.d(TAG,"send_reboot=="+t);


        Intent intent=new Intent();
        // intent.setAction("android.intent.action.reboot"); //android.yide.intent.action.reboot
        intent.setAction("android.yide.intent.action.reboot");
        //intent.putExtra("keycode",1234);
        this.sendBroadcast(intent);


    }
    public void send_bl(){
        Log.d(TAG,"send_bl");

        Intent intent=new Intent();
        intent.setAction("android.yide.intent.action.backlight");
        if(!mBtnBl.isChecked()) intent.putExtra("enable",false);/*关闭背光*/
        else intent.putExtra("enable",true);/*打开背光*/
        this.sendBroadcast(intent);


    }

    public void send_time_set(){


        Log.d(TAG,"send_time_set");
        Intent intent=new Intent("android.56iq.intent.action.settime");
        //Intent intent=new Intent("android.yide.intent.action.systemtime");
        //Intent intent=new Intent("android.intent.action.settime");
        int[] timeArray = {2017,2,16,9,0,0}; //年-月-日-时-分-秒
        intent.putExtra("settime",timeArray);
        intent.putExtra("enable",true); //使能开关
        sendBroadcast(intent);
        this.sendBroadcast(intent);


        int i = 123456;




        int value=60;//0x7fffffff;
        String mode="autoon";

        //integer.toString(i);
        mode = mode + String.format("%08x",value);//Integer.toString(value);//String.valueOf(value);


        //set_power_auto(60);
        Log.d("mode","mode=="+mode);

    }

    public void send_time_zone(){
        Intent intent=new Intent("android.intent.action.sendkey");
        intent.putExtra("keycode",1244);
        intent.putExtra("timezone","GMT+02:00");
        this.sendBroadcast(intent);
    }

    public void send_fac(){

        Log.d(TAG,"send_fac");
        Intent intent=new Intent();
        intent.setAction("android.yide.intent.action.recovery");
        intent.putExtra("enable",false);
        this.sendBroadcast(intent);

    }

    public void send_timezone(){

	   /*Log.d(TAG,"send_timezone");
	   Intent intent=new Intent("android.intent.action.sendkey");
	   intent.putExtra("keycode",1244);
	   intent.putExtra("timezone","GMT+02:00");
	   this.sendBroadcast(intent);
	   */

        Intent intent = new Intent("android.yide.intent.action.setpoweronoff");
        int[] timeonArray = {2017,2,16, 15,22}; //下次开机具体日期时间，即在 2014/10/1 8:30 会开机
        int[] timeoffArray = {2017,2,16, 15,19}; //下次关机具体日期时间，即在 2014/9/1 8:25 会关机
        intent.putExtra("timeOn",timeonArray);
        intent.putExtra("timeOff",timeoffArray);
        intent.putExtra("enable",true); //使能开关机功能，设为 false,则为关闭
        sendBroadcast(intent);

    }

    public void send_screen(){

        Log.d(TAG,"send_screen");
        Intent intent=new Intent("rk.android.screenshot.action");
        String path="/mnt/sdcard/Pictures/1.jpg";
        intent.putExtra("path",path);
        this.sendBroadcast(intent);

    }

    public void send_shutdown(){

        Log.d(TAG,"send_shutdown");
        // Intent intent=new Intent("android.intent.action.shutdown");
        Intent intent=new Intent("android.yide.intent.action.shutdown");
        //intent.putExtra("keycode",1235);
        this.sendBroadcast(intent);

    }

    public void send_poweron(){

        Log.d(TAG,"send_poweron");
	 /*  Intent intent=new Intent("android.intent.action.sendkey");
	   intent.putExtra("keycode",1247);
	   intent.putExtra("powerontime","2016/10/0112:30");//定时开机时间
	   this.sendBroadcast(intent);*/
        //  Intent intent = new Intent("android.intent.action.setpoweronoff");
	   /*
	     Intent intent = new Intent("android.intent.action.setpoweronoff");
	   int[] timeonArray = {2014,10,1, 8,34}; //下次开机具体日期时间，即在 2014/10/1 8:30 会开机
	   int[] timeoffArray = {2014,10,1, 8,32}; //下次关机具体日期时间，即在 2014/9/1 8:25 会关机
	   intent.putExtra("timeon",timeonArray);
	   intent.putExtra("timeoff",timeoffArray);
	   intent.putExtra("enable",true); //使能开关机功能，设为 false,则为关闭
	   sendBroadcast(intent);

	    */
        //android.56iq.intent.action.setpoweronoff

        Intent intent = new Intent("android.intent.action.setpoweronoff");

        // Intent intent = new Intent("android.56iq.intent.action.setpoweronoff");
        int[] timeonArray = {2017,2,16, 9,4,0}; //下次开机具体日期时间，即在 2014/10/1 8:30 会开机
        int[] timeoffArray = {2017,2,16, 9,2,0}; //下次关机具体日期时间，即在 2014/9/1 8:25 会关机
        intent.putExtra("timeon",timeonArray);
        intent.putExtra("timeoff",timeoffArray);
        intent.putExtra("enable",true); //使能开关机功能，设为 false,则为关闭
        sendBroadcast(intent);

    }

    public void send_poweroncc(){

        Log.d(TAG,"send_poweroncc");
        img();

        // Message msg1 = new Message();
        //   msg1.what = 1;
        //   m2Handler.sendMessage(msg1);

        //  exe_img();
        //  Log.d(TAG,"send_poweroncc-222");
        //  Intent intent=new Intent("android.intent.action.otaupdate");
        //   intent.putExtra("path","/mnt/internal_sd/uuuu.img");
        //  intent.putExtra("path","/sdcard/Download/update.zip");
        //   this.sendBroadcast(intent);





    }

    void ota(){
        // Intent intent=new Intent("android.intent.action.otaupdate");
        //  intent.putExtra("path","/mnt/internal_sd/uuuu.img");
        //   intent.putExtra("path","/sdcard/Download/update.zip");
        //  this.sendBroadcast(intent);
        Log.d("lizzz","otaaaaa----\n");

        //  Intent intentOne = new Intent("com.yx.upso.LocalService", "com.yx.upso");
        // startService(intentOne);


        Intent intent = new Intent();
        ComponentName componentName = new ComponentName("com.yx.upso", "com.yx.upso.LocalService");
        intent.setComponent(componentName);
        startService(intent);

        try
        {
            Thread.sleep(100);
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }


        Intent intent2=new Intent("android.intent.action.updateso");
        this.sendBroadcast(intent2);
    }

    public void send_setup(){

        Log.d(TAG,"send_setup");
        Intent intent=new Intent("android.intent.action.sendkey");
        intent.putExtra("keycode",1245);
        intent.putExtra("apkpath","/mnt/sdcard/tengxunshipin.apk");
        this.sendBroadcast(intent);

    }


    static int i=0;

    public void send_rotate(){

        Log.d(TAG,"send_rotate");


        if(i>3) i=0;

        Intent intent=new Intent();
        intent.setAction("android.intent.action.sendkey");
        intent.putExtra("keycode",1242);

        if(i==0) {
            mBtRotate.setText("Rotate 0");
            intent.putExtra("screen_num",Surface.ROTATION_0);
        }
        else if(i==1){
            mBtRotate.setText("Rotate 90");
            intent.putExtra("screen_num",Surface.ROTATION_90);
        }
        else if(i==2) {
            mBtRotate.setText("Rotate 180");
            intent.putExtra("screen_num",Surface.ROTATION_180);
        }
        else if(i==3) {
            mBtRotate.setText("Rotate 270");
            intent.putExtra("screen_num",Surface.ROTATION_270);
        }

        this.sendBroadcast(intent);

        Log.d(TAG,"send_rotate===="+i);
        i++;

    }



    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.reboot:
                send_reboot();
                break;
            case R.id.bl:
                send_bl();
                break;
            case R.id.nav:
                send_nav();
                break;
            case R.id.hdmi:
                send_hdmi();
                break;
            case R.id.wifi:
                send_wifi();
                break;

            case R.id.fac:
                send_fac();
                break;
            case R.id.time_set:

                send_time_set();
                break;

            case R.id.rotate:

                send_rotate();
                break;
            case R.id.timezone_set:

                send_timezone();
                break;

            case R.id.ScreenShot:

                send_screen();

                break;

            case R.id.shutdown:

                send_shutdown();

                break;


            case R.id.PowerOn:

                send_poweron();

                break;

            case R.id.PowerOnCC:

                send_poweroncc();

                break;



            case R.id.Setup:

                send_setup();

                break;



            case R.id.yx_onoff:

            { /* Intent intent = new Intent("android.intent.action.setpoweronoff");
	   int[] timeonArray = {2017,2,16, 15,22}; //下次开机具体日期时间，即在 2014/10/1 8:30 会开机
	   int[] timeoffArray = {2017,2,16, 15,21}; //下次关机具体日期时间，即在 2014/9/1 8:25 会关机
	   intent.putExtra("timeon",timeonArray);
	   intent.putExtra("timeoff",timeoffArray);
	   intent.putExtra("enable",true); //使能开关机功能，设为 false,则为关闭
	   sendBroadcast(intent);*/
                Time tm1,tm2;
                tm1=new Time();
                tm2=new Time();

                long now=System.currentTimeMillis();


                Log.d("ddd","now==="+now/1000);

                tm1.set(now+180*1000);

                tm2.set(now+60000);

                Log.d("t1","y="+tm1.year+"m"+tm1.month+"d+"+tm1.monthDay+"h="+tm1.hour+"m="+tm1.minute);
                Log.d("t2","y="+tm2.year+"m"+tm2.month+"d+"+tm2.monthDay+"h="+tm2.hour+"m="+tm2.minute);
                int[] t1 = {tm1.year,tm1.month+1,tm1.monthDay,tm1.hour,tm1.minute};
                int[] t2 = {tm2.year,tm2.month+1,tm2.monthDay,tm2.hour,tm2.minute};
                Intent intent = new Intent();
                intent.setAction("android.intent.action.setpoweronoff");
                intent.putExtra("timeon",t1);
                intent.putExtra("timeoff",t2);
                intent.putExtra("enable", true);
                sendBroadcast(intent);
            }
            break;


            case R.id.yx_time_set:

            { Intent intent=new Intent("android.intent.action.settime");
                int[] timeArray = {2017,2,16,15,20,0}; //年-月-日-时-分-秒
                intent.putExtra("settime",timeArray);
                intent.putExtra("enable",true); //使能开关
                sendBroadcast(intent);
                this.sendBroadcast(intent);
            }

            break;

            case R.id.yx_shutdown:
            {
                Intent intent = new Intent("android.intent.action.shutdown");
                sendBroadcast(intent);
            }

            break;

            case R.id.yx_reboot:
            {
                Intent intent = new Intent("android.intent.action.reboot");
                sendBroadcast(intent);
            }

            break;


            case R.id.yx_show_bar:
            {
                manager.setNavBarNew(true);
            }
            break;


            case R.id.yx_hide_bar:
            {
                manager.setNavBarNew(false);
            }
            break;

            case R.id.yx_bl:
            {
                Intent intent=new Intent();
                intent.setAction("android.yide.intent.action.backlight");
                if(!yx_bl.isChecked()) intent.putExtra("enable",false);/*关闭背光*/
                else intent.putExtra("enable",true);/*打开背光*/
                this.sendBroadcast(intent);
            }
            break;


            case R.id.yx_fac_reset:
            {
                Intent intent = new Intent("android.yide.intent.action.recovery");
                intent.putExtra("enable" , true); // true:确认恢复 ， false:取消恢复
                sendBroadcast(intent);
            }
            break;

            case R.id.yx_screen_shot:
            {
                Intent intent = new Intent("rk.android.screenshot.action");
                sendBroadcast(intent);
            }
            break;
            case R.id.yx_reset4g:
            {
                Intent intent = new Intent("android.intent.action.reset4g");
                sendBroadcast(intent);
            }
            break;


            case R.id.yx_io1out:
            {
                if(yx_io1out.isChecked()) {set_oem_gpio(0x11); }
                else set_oem_gpio(0x10);
                break;
            }
            case R.id.yx_io2out:
            {
                if(yx_io2out.isChecked()) {set_oem_gpio(0x21); }
                else set_oem_gpio(0x20);
                break;
            }
            case R.id.yx_io3out:
            {
                if(yx_io3out.isChecked()) {set_oem_gpio(0x31); }
                else set_oem_gpio(0x30);
                break;
            }
            case R.id.yx_io4out:
            {
                if(yx_io4out.isChecked()) {set_oem_gpio(0x41); }
                else set_oem_gpio(0x40);

            }
            break;
            case R.id.yx_io5out:
            {
                if(yx_io5out.isChecked()) {set_oem_gpio(0x51); }
                else set_oem_gpio(0x50);
            }
            break;
            case R.id.yx_io6out:
            {
                if(yx_io6out.isChecked()) {set_oem_gpio(0x61); }
                else set_oem_gpio(0x60);
            }
            break;


            case R.id.yx_io7out:
            {
                if(yx_io7out.isChecked()) {set_oem_gpio(0x71); }
                else set_oem_gpio(0x70);
            }
            break;


            case R.id.yx_io8out:
            {
                if(yx_io8out.isChecked()) {set_oem_gpio(0x81); }
                else set_oem_gpio(0x80);
            }
            break;


            case R.id.yx_io9out:
            {
                if(yx_io9out.isChecked()) {set_oem_gpio(0x91); }
                else set_oem_gpio(0x90);
            }
            break;


            case R.id.yx_io1in:
            {
               // if(ReadFromIO(1)==1) {yx_io1in.setText("1in H");}
               // else yx_io1in.setText("1in L");
            }
            break;

            case R.id.yx_io2in:
            {
                if(ReadFromIO(2)==1) {yx_io2in.setText("2in H");}
                else yx_io2in.setText("2in L");
            }
            break;

            case R.id.yx_io3in:
            {
                if(ReadFromIO(3)==1) {yx_io3in.setText("3in H");}
                else yx_io3in.setText("3in L");
            }
            break;

            case R.id.yx_io4in:
            {
                if(ReadFromIO(4)==1) {yx_io4in.setText("4in H");}
                else yx_io4in.setText("4in L");
            }
            break;


            case R.id.yx_io5in:
            {
                if(ReadFromIO(5)==1) {yx_io5in.setText("5in H");}
                else yx_io5in.setText("5in L");
            }
            break;


            case R.id.yx_io6in:
            {
                if(ReadFromIO(6)==1) {yx_io6in.setText("6in H");}
                else yx_io6in.setText("6in L");
            }
            break;


            case R.id.yx_io7in:
            {
                if(ReadFromIO(7)==1) {yx_io7in.setText("7in H");}
                else yx_io7in.setText("7in L");
            }
            break;


            case R.id.yx_io8in:
            {
                if(ReadFromIO(8)==1) {yx_io8in.setText("8in H");}
                else yx_io8in.setText("8in L");
            }
            break;


            case R.id.yx_pm:
            {
                //excuteSuCMD();
                // ttt();
                ttt2();

                // cp_avi();

                // send_moki();
                // send_root();

                //mkmnt();
            }
            break;



            case R.id.stop_ril:
            {
                //excuteSuCMD();
                // ttt();
                //stop_ril();
                // start_app();
                // send_ray_time();
                //set_30_onoff();

                // doRotate(90);

                // exe_screenshot();

                exe_power();
            }
            break;


            case R.id.lock:
            {
                lock_ttt();
            }
            break;


            case R.id.start_ril:
            {
                start_ril();
            }
            break;

            case R.id.vol:
            {
                AudioManager audioManager = (AudioManager) getSystemService(Service.AUDIO_SERVICE);
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                        audioManager.getStreamVolume(AudioManager.STREAM_MUSIC), AudioManager.FLAG_SHOW_UI);

            }
            break;

            case R.id.brightness:
            {
                // Intent intent = new Intent("com.android.systemui","com.android.systemui.settings.BrightnessDialog");
                // startActivity(intent);

                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.settings.BrightnessDialog");
                intent.setComponent(cn);
                startActivity(intent);
            }
            break;

            case R.id.enht_sleep:
            {
                Intent sleepIntent = new Intent("enht.face.sleep");
                sendBroadcast(sleepIntent);
            }
            break;

            case R.id.enht_wakeup:
            {
                Intent wakeupIntent = new Intent("enht.face.wakeup");
                sendBroadcast(wakeupIntent);
            }
            break;

            case R.id.enht_reboot:
            {
                Intent wakeupIntent = new Intent("rk.android.reboot.action");
                sendBroadcast(wakeupIntent);
            }
            break;


            case R.id.wdt:
            {
                wdt();
            }
            break;

            case R.id.ota:
            {
                ota();
                break;
            }


            case R.id.fan:
            {
                if(fan.isChecked()) {exe_su_cmd("echo fan1 > /proc/oem_gpio");}
                else exe_su_cmd("echo fan0 > /proc/oem_gpio");
                break;
            }

            case R.id.light:
            {
                if(light.isChecked()) exe_su_cmd("echo light1 > /proc/oem_gpio");
                else exe_su_cmd("echo light0 > /proc/oem_gpio");
                break;
            }
            case R.id.ledr:
            {
                if(led_r.isChecked()) exe_su_cmd("echo ledr1 > /proc/oem_gpio");
                else exe_su_cmd("echo ledr0 > /proc/oem_gpio");
                break;
            }
            case R.id.ledg:
            {
                if(led_g.isChecked()) exe_su_cmd("echo ledg1 > /proc/oem_gpio");
                else exe_su_cmd("echo ledg0 > /proc/oem_gpio");
            }
            break;
            case R.id.ledb:
            {
                if(led_b.isChecked()) exe_su_cmd("echo ledb1 > /proc/oem_gpio");
                else exe_su_cmd("echo ledb0 > /proc/oem_gpio");
            }
            break;
            case R.id.ledir:
            {
                if(led_ir.isChecked()) exe_su_cmd("echo ledir1 > /proc/oem_gpio");
                else exe_su_cmd("echo ledir0 > /proc/oem_gpio");
            }
            break;
            case R.id.relay:
            {
                if(bt_relay.isChecked()) exe_su_cmd("echo relay1 > /proc/oem_gpio");
                else exe_su_cmd("echo relay0 > /proc/oem_gpio");
            }
            break;
            case R.id.ipadress:

                String ip =getLocalIpAddress();
                Log.i("fan","press get ip ="+ip);
                mdis_IP.setText(ip);
                break;
            default:
                break;
        }
    }
    public String getLocalIpAddress() {
        try {
            String ipv4;
            ArrayList<NetworkInterface> nilist = Collections.list(NetworkInterface.getNetworkInterfaces());
            for (NetworkInterface ni: nilist)
            {
                ArrayList<InetAddress> ialist = Collections.list(ni.getInetAddresses());
                for (InetAddress address: ialist){
                    if (!address.isLoopbackAddress() )
                    {
                        Log.i("fan","addr network="+address.getHostAddress());
                        return address.getHostAddress();
                    }
                }
            }
        } catch (SocketException ex) {
            Log.i("fan", ex.toString());
        }
        return null;
    }
    public static  void exe_cmd(String cmd){

        Process process2 = null;
        DataOutputStream dos = null;
        try{
            process2 = Runtime.getRuntime().exec("su");
            dos = new DataOutputStream(process2.getOutputStream());
            dos.writeBytes(cmd);//"input keyevent 26");
            dos.flush();
            dos.close();
        }
        catch (Exception e) {

            e.printStackTrace();
        }

    }
    public static void set_oem_gpio(int value){

        String cmd1="";
        String cmd2="";
        if(value==0x10 ){cmd1="echo io10 >/proc/oem_gpio";cmd2="echo 0 > /sys/class/leds/IO1/brightness";}
        else if(value==0x11){cmd2="echo 1 > /sys/class/leds/IO1/brightness";cmd1="echo io11 >/proc/oem_gpio";}

        else if(value==0x20){	cmd2="echo 0 > /sys/class/leds/IO2/brightness";cmd1="echo io20 >/proc/oem_gpio";}
        else if(value==0x21){	cmd2="echo 1 > /sys/class/leds/IO2/brightness";cmd1="echo io21 >/proc/oem_gpio";}
        else if(value==0x30){	cmd2="echo 0 > /sys/class/leds/IO3/brightness";cmd1="echo io30 >/proc/oem_gpio";}
        else if(value==0x31){	cmd2="echo 1 > /sys/class/leds/IO3/brightness";cmd1="echo io31 >/proc/oem_gpio";}
        else if(value==0x40){	cmd2="echo 0 > /sys/class/leds/IO4/brightness";cmd1="echo io40 >/proc/oem_gpio";}
        else if(value==0x41){	cmd2="echo 1 > /sys/class/leds/IO4/brightness";cmd1="echo io41 >/proc/oem_gpio";}
        else if(value==0x50){	cmd2="echo 0 > /sys/class/leds/IO5/brightness";cmd1="echo io50 >/proc/oem_gpio";}
        else if(value==0x51){	cmd2="echo 1 > /sys/class/leds/IO5/brightness";cmd1="echo io51 >/proc/oem_gpio";}
        else if(value==0x60){	cmd2="echo 0 > /sys/class/leds/IO6/brightness";cmd1="echo io60 >/proc/oem_gpio";}
        else if(value==0x61){	cmd2="echo 1 > /sys/class/leds/IO6/brightness";cmd1="echo io61 >/proc/oem_gpio";}
        else if(value==0x70){	cmd2="echo 0 > /sys/class/leds/IO7/brightness";cmd1="echo io70 >/proc/oem_gpio";}
        else if(value==0x71){	cmd2="echo 1 > /sys/class/leds/IO7/brightness";cmd1="echo io71 >/proc/oem_gpio";}
        else if(value==0x80){	cmd2="echo 0 > /sys/class/leds/IO8/brightness";cmd1="echo io80 >/proc/oem_gpio";}
        else if(value==0x81){	cmd2="echo 1 > /sys/class/leds/IO8/brightness";cmd1="echo io81 >/proc/oem_gpio";}
        else if(value==0x90){	cmd2="echo 0 > /sys/class/leds/IO9/brightness";cmd1="echo io90 >/proc/oem_gpio";}
        else if(value==0x91){	cmd2="echo 1 > /sys/class/leds/IO9/brightness";cmd1="echo io91 >/proc/oem_gpio";}

     exe_cmd(cmd1);exe_cmd(cmd2);

    }

    void wdt(){
        String mode="0";
        try {

            Log.d("liz","mode==="+mode);
            FileOutputStream fops = new FileOutputStream("/proc/wdt");
            fops.write(mode.getBytes());
            fops.flush();
            fops.close();

        } catch (FileNotFoundException e) {
            Log.d("err", "found error");
        } catch (IOException e) {
            Log.d("err", "IO error");
        }



        try {
            FileInputStream fin=null;
            fin= new FileInputStream("/proc/oem_gpio");

            //  Log.d("rrr=","fin"+fin);
            BufferedReader reader= new BufferedReader(new InputStreamReader(fin));
            String config = reader.readLine();
            fin.close();
            Log.d("rrrr====","****************\n");

            Log.d("rrrr====","read==tt=="+config);

            Log.d("rrrr====","****************\n");

            String s1[]=config.split(",");


            Log.d("rrrr====","read=11="+s1[0]);

            Log.d("rrrr====","read==22=="+s1[1]);


            float Humidity = Integer.parseInt(s1[0]);

            Humidity = (Humidity*1000/1024/1024)/10;


            float Temperature = Integer.parseInt(s1[1]);

            Temperature = (Temperature*200*10/1024/1024-500)/10;




            textView1.setText("hum="+Float.toString(Humidity)+"temp="+Float.toString(Temperature));
            System.out.println("Humidity= "+Humidity);
            System.out.println("Temperature= "+Temperature);
        } catch(IOException e) {
            e.printStackTrace();

        }


    }





    public int ReadFromIO(int io) {

        try {
            FileInputStream fin=null;
            if(io==1)fin= new FileInputStream("/proc/yx_gpio/gpio_io1");
            else if(io==2)fin= new FileInputStream("/proc/yx_gpio/gpio_io2");
            else if(io==3)fin= new FileInputStream("/proc/yx_gpio/gpio_io3");
            else if(io==4)fin= new FileInputStream("/proc/yx_gpio/gpio_io4");
            else if(io==5)fin= new FileInputStream("/proc/yx_gpio/gpio_io5");
            else if(io==6)fin= new FileInputStream("/proc/yx_gpio/gpio_io6");
            else if(io==7)fin= new FileInputStream("/proc/yx_gpio/gpio_io7");
            else if(io==8)fin= new FileInputStream("/proc/yx_gpio/gpio_io8");

            //  Log.d("rrr=","fin"+fin);
            BufferedReader reader= new BufferedReader(new InputStreamReader(fin));
            String config = reader.readLine();
            fin.close();
            Log.d("rrrr====","****************\n");

            Log.d("rrrr====","read===="+config);

            Log.d("rrrr====","****************\n");


            if(config.equals("1")) {return 1;}
            else if(config.equals("0")) {return 0;}

            return -1;
        } catch(IOException e) {
            e.printStackTrace();

        }

        return -1;
    }

    public static void set_power_auto(int value){

        String mode="autoon";

        mode=mode + String.format("%08x",value);


        Log.d("mode","mode1234=="+mode);




        try {
            FileOutputStream fops = new FileOutputStream("/proc/oem_gpio");
            fops.write(mode.getBytes());
            fops.flush();
            fops.close();

        } catch (FileNotFoundException e) {
            Log.d("err", "found error");
        } catch (IOException e) {
            Log.d("err", "IO error");
        }

    }


    private final BroadcastReceiver boot2 = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context,Intent intent){
            Log.i("Receiver2222", "onReceive8888:" + intent.getAction());

            if (intent.getAction().equals("MyReceiver_key")) {

                String status = intent.getStringExtra("status");

                Log.i("Receiver-key", "key=val=" + status);

                textView1.setText(status);
            }

        }
    };


    protected static void excuteSuCMD() {
        Process process = null;
        OutputStream out = null;
        InputStream in = null;
        String currentTempFilePath = "/sdcard/Download/app-debug.apk";
        try {
            // 请求root
            process = Runtime.getRuntime().exec("su");


            Log.i("Receiver-key", "get run11111\n");
            out = process.getOutputStream();
            // 调用安装

            Log.i("Receiver-key", "get run2222\n");

            out.write(("/system/bin/reboot").getBytes());

            //	Process proc = rt.exec("pm install -i codepath.apps.demointroandroid --user 0 /sdcard/Download/app-debug.apk");
            //	out.write(("pm install -i codepath.apps.demointroandroid --user 0 /sdcard/Download/app-debug.apk").getBytes());
            //  out.write(("ps"+"\n").getBytes());
            //   out.write(("pm install -r" + currentTempFilePath + "\n").getBytes());
            Log.i("Receiver-key", "get run33333\n");
            in = process.getInputStream();
            int len = 0;
            byte[] bs = new byte[256];
            while (-1 != (len = in.read(bs))) {
                String state = new String(bs, 0, len);
                if (state.equals("Success\n")) {
                    //安装成功后的操作
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.flush();
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    void ttt(){

        Log.i("Receiver-key", "ttt\n");
        try {
            Runtime rt = Runtime.getRuntime();
            //Process proc = rt.exec("pm install -r /sdcard/Download/app-debug.apk");
            Process proc = rt.exec("cp  /system/005.avi /sdcard/0/");
        }
        catch (Exception e) {

            e.printStackTrace();
        }
    }


    void cp_avi(){

        File file_0 = new File("/sdcard/0");

        File file_avi = new File("/sdcard/0/005.avi");

        if (file_0.exists()) {
            if (file_0.isDirectory()) {
                System.out.println("dir exists");
            } else {
                System.out.println("the same name file exists, can not create dir");
            }
        } else {
            System.out.println("dir not exists, create it ...");
            file_0.mkdir();
        }


        if (file_avi.exists()) {
            System.out.println("file exists");
        }
        else {

            System.out.println("cp file---0000");
            ttt();
            System.out.println("cp file---ok");
        }


    }


    void exe_screenshot(){

        Log.i("Receiver-key", "ttt\n");
        try {
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("screencap -p /sdcard/Download/2.jpg");
        }
        catch (Exception e) {

            e.printStackTrace();
        }
    }

    void start_ril(){

        Log.i("Receiver-key", "ttt\n");
        try {
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("start ril-daemon");
        }
        catch (Exception e) {

            e.printStackTrace();
        }
    }

    void stop_ril(){

        Log.i("Receiver-key", "ttt\n");
        try {
            Runtime rt = Runtime.getRuntime();
            //Process proc = rt.exec("system/bin/stop_ril.sh");

            Process proc = rt.exec("am start -n net.yet.campusdev/com.abe.bathsystem.android.SplashActivity");
        }
        catch (Exception e) {

            e.printStackTrace();
        }
    }

    void ttt2(){
        Process process2 = null;
        DataOutputStream dos = null;
        try{
            process2 = Runtime.getRuntime().exec("su");
            dos = new DataOutputStream(process2.getOutputStream());

            dos.writeBytes("chmod 666 /sys/class/net/eth0/carrier");

            //dos.writeBytes("pm install -r /sdcard/Download/app-debug.apk");
            //	dos.writeBytes("pm install -i codepath.apps.demointroandroid --user 0 /sdcard/Download/app-debug.apk");
            dos.flush();
            dos.close();
        }
        catch (Exception e) {

            e.printStackTrace();
        }

    }

    void start_app(){


	/*Log.d("liz","start_app=======\n");
   	Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName("net.yet.campusdev", "net.yet.campusdev.com.abe.bathsystem.android.SplashActivity");
intent.setComponent(cn);
	this.startActivity(intent);
	*/

        Process process2 = null;
        DataOutputStream dos = null;
        try{
            process2 = Runtime.getRuntime().exec("su");
            dos = new DataOutputStream(process2.getOutputStream());
            dos.writeBytes("input keyevent 26");
            //dos.writeBytes("am start -n net.yet.campusdev/com.abe.bathsystem.android.SplashActivity");
//	dos.writeBytes("pm install -i codepath.apps.demointroandroid --user 0 /sdcard/Download/app-debug.apk");
            dos.flush();
            dos.close();
        }
        catch (Exception e) {

            e.printStackTrace();
        }

    }

    void send_ray_time(){
        Intent intent= new Intent("MyReceiver_key");
        int time=30;
        intent.putExtra("ray_time",time);
        sendBroadcast(intent);
    }
    void set_30_onoff(){
        Time tm1,tm2;
        tm1=new Time();
        tm2=new Time();

        long now=System.currentTimeMillis();

        tm1.set(now+240000);

        tm2.set(now+120000);

        Log.d("t1","y="+tm1.year+"m"+tm1.month+"d+"+tm1.monthDay+"h="+tm1.hour+"m="+tm1.minute);
        Log.d("t2","y="+tm2.year+"m"+tm2.month+"d+"+tm2.monthDay+"h="+tm2.hour+"m="+tm2.minute);
        int[] t1 = {tm1.year,tm1.month+1,tm1.monthDay,tm1.hour,tm1.minute};
        int[] t2 = {tm2.year,tm2.month+1,tm2.monthDay,tm2.hour,tm2.minute};
        Intent intent = new Intent();
        intent.setAction("android.intent.action.setpoweronoff");
        intent.putExtra("timeon",t1);
        intent.putExtra("timeoff",t2);
        intent.putExtra("enable", true);
        this.sendBroadcast(intent);
    }



    public Bitmap rotatePicture(final Bitmap bitmap, final int degree) {
        Matrix matrix = new Matrix();

        matrix.postScale(-1, 1);
        // matrix.postRotate(degree);
        Bitmap resizeBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

        return resizeBitmap;
    }


    public boolean saveBmpToPath(final Bitmap bitmap, final String filePath) {
        if (bitmap == null || filePath == null) {
            return false;
        }
        boolean result = false; //默认结果
        File file = new File(filePath);
        OutputStream outputStream = null; //文件输出流
        try {
            outputStream = new FileOutputStream(file);
            result = bitmap.compress(Bitmap.CompressFormat.JPEG, 96, outputStream); //将图片压缩为JPEG格式写到文件输出流，100是最大的质量程度
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close(); //关闭输出流
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }

    public boolean doRotate(final int degree) {
        //得到Gallery当前选中的item的数据
        //   FileInfo fileInfo = (FileInfo) mPictureGallery.getSelectedItem();
        //第一步
        Bitmap picture = BitmapFactory.decodeFile("/sdcard/DCIM/Camera/IMG_20181117_175717.jpg");
        //第二步
        Bitmap resizePicture = rotatePicture(picture, degree);
        //第三步
        saveBmpToPath(resizePicture, "/sdcard/DCIM/Camera/1.jpg");
        //更新Gallery显示
        // mPictureGallery.updateData();

        return false;
    }


    void send_moki(){
        Intent intent= new Intent("MyReceiver_key");
        int time=30;
        intent.putExtra("hidemoki","1");
        sendBroadcast(intent);
    }

    void send_root(){
        Intent intent= new Intent("MyReceiver_key");
        int time=30;
        intent.putExtra("mokiroot","1");
        sendBroadcast(intent);
    }






    // "/storage/CD4E-DE59"


    void exe_su_cmd(String cmd){

        Log.d("su","exe_su_cmd");
        Process process2 = null;
        DataOutputStream dos = null;
        try{
            process2 = Runtime.getRuntime().exec("su");
            dos = new DataOutputStream(process2.getOutputStream());
            dos.writeBytes(cmd);
            //	dos.writeBytes("pm install -i codepath.apps.demointroandroid --user 0 /sdcard/Download/app-debug.apk");
            dos.flush();
            dos.close();
        }
        catch (Exception e) {

            e.printStackTrace();
        }

    }


    void mkmnt(){


        Intent intent = new Intent(Intent.ACTION_VIEW);
        // String path = "/mnt/sdcard/Download/wdzrong.mp4";//Environment.getExternalStorageDirectory().getPath()+ "/1.mp4";//该路径可以自定义
        //  /mnt/usb_storage/USB_DISK1/udisk0
        // String path = "/mnt/usb_storage/USB_DISK1/udisk0/wdzrong.mp4";

        String path = "/mnt/usb_storage/USB_DISK1/udisk0/wdzrong.mp4";

        //  String path = "/storage/sata/wdzrong.mp4";
        File file = new File(path);
        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, "video/*");
        startActivity(intent);

        //  ttt2();
        //  exe_su_cmd("lcdlightservice /storage/CD4E-DE59");

        //   exe_su_cmd("mkdir -p /mnt/usb_storage/USB_DISK8/udisk0");

        // exe_su_cmd("busybox mount /storage/CD4E-DE59 /mnt/usb_storage/USB_DISK8/udisk0");
    }



    public int get_temp() {

        try {
            FileInputStream fin=null;
            fin= new FileInputStream("/proc/oem_gpio");

            //  Log.d("rrr=","fin"+fin);
            BufferedReader reader= new BufferedReader(new InputStreamReader(fin));
            String config = reader.readLine();
            fin.close();
            Log.d("rrrr====","****************\n");

            Log.d("rrrr====","read==tt=="+config);

            Log.d("rrrr====","****************\n");

            int t= Integer.parseInt(config);

            float temp=(float) t;
            temp*=175.72f;
            temp/=65536.0f;
            temp-=46.85f;

            System.out.println("temp= "+temp);

            textView1.setText(Float.toString(temp));



            return -1;
        } catch(IOException e) {
            e.printStackTrace();

        }

        return -1;
    }


    public int get_hum() {

        try {
            FileInputStream fin=null;
            fin= new FileInputStream("/proc/humidity");

            //  Log.d("rrr=","fin"+fin);
            BufferedReader reader= new BufferedReader(new InputStreamReader(fin));
            String config = reader.readLine();
            fin.close();
            Log.d("rrrr====","****************\n");

            Log.d("rrrr====","read=hh==="+config);

            Log.d("rrrr====","****************\n");

            int t= Integer.parseInt(config);

            float temp=(float) t;
            temp*=125;
            temp/=65536.0f;
            temp-=6.0f;

            System.out.println("hum= "+temp);



            return -1;
        } catch(IOException e) {
            e.printStackTrace();

        }

        return -1;
    }



    public int get_proximity() {

        try {
            FileInputStream fin=null;
            fin= new FileInputStream("/proc/proximity");

            //  Log.d("rrr=","fin"+fin);
            BufferedReader reader= new BufferedReader(new InputStreamReader(fin));
            String config = reader.readLine();
            fin.close();
            Log.d("rrrr====","****************\n");

            Log.d("rrrr====","read=hh==="+config);

            Log.d("rrrr====","****************\n");

            int t= Integer.parseInt(config);



            System.out.println("prox= "+t);



            return -1;
        } catch(IOException e) {
            e.printStackTrace();

        }

        return -1;
    }

    // echo 1 > /sys/class/backlight/rk28_bl/bl_power close backlight
    //echo 0 > /sys/class/backlight/rk28_bl/bl_power open backlight

    public static boolean isApkInDebug(Context context) {

        try {

            ApplicationInfo info = context.getApplicationInfo();

            return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;

        } catch (Exception e) {

            return false;

        }
    }


    ///mnt/usb_storage/USB_DISK5/udisk0/uuuu.img


    void exe_img(){
        Process process2 = null;
        DataOutputStream dos = null;
        try{
            process2 = Runtime.getRuntime().exec("su");
            dos = new DataOutputStream(process2.getOutputStream());

            dos.writeBytes("cp /mnt/usb_storage/USB_DISK5/udisk0/uuuu.img /sdcard/uuuu.img");

            //dos.writeBytes("pm install -r /sdcard/Download/app-debug.apk");
            //	dos.writeBytes("pm install -i codepath.apps.demointroandroid --user 0 /sdcard/Download/app-debug.apk");
            dos.flush();
            dos.close();


            //   int status = process2.waitFor();
            Log.d(TAG,"cp--ooooo----------");

        }
        catch (Exception e) {

            e.printStackTrace();
        }
	    	/*
		   try{
			   mappedBuffer();
			   Log.d(TAG,"cp--ooooo----------\n");
		   }
		   catch (Exception e) {

			   e.printStackTrace();
	   }*/
    }


    private Handler m2Handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:

                    exe_img();

                    Message msg1 = new Message();
                    msg1.what = 2;
                    m2Handler.sendMessage(msg1);

                    break;

                case 2:



                    break;
                default:
                    break;

            }
        }
    };


    public static void mappedBuffer() throws IOException{
        long start=System.currentTimeMillis();
        FileChannel read = new FileInputStream("/mnt/usb_storage/USB_DISK5/udisk0/uuuu.img").getChannel();
        FileChannel writer = new RandomAccessFile("/sdcard/uuuu.img","rw").getChannel();
        long i = 0;
        long size = read.size()/30;
        ByteBuffer bb,cc = null;
        while(i<read.size()&&(read.size()-i)>size){
            bb = read.map(FileChannel.MapMode.READ_ONLY, i, size);
            cc = writer.map(FileChannel.MapMode.READ_WRITE, i, size);
            cc.put(bb);
            i+=size;
            bb.clear();
            cc.clear();
        }
        bb = read.map(FileChannel.MapMode.READ_ONLY, i, read.size()-i);
        cc.put(bb);
        bb.clear();
        cc.clear();
        read.close();
        writer.close();
        long end=System.currentTimeMillis();
        System.out.println("用时："+(end-start)+"毫秒");
    }


    void exe_power(){
        Process process2 = null;
        DataOutputStream dos = null;
        try{
            process2 = Runtime.getRuntime().exec("su");
            dos = new DataOutputStream(process2.getOutputStream());

            dos.writeBytes("sh /system/bin/longpower.sh");

            //dos.writeBytes("pm install -r /sdcard/Download/app-debug.apk");
            //	dos.writeBytes("pm install -i codepath.apps.demointroandroid --user 0 /sdcard/Download/app-debug.apk");
            dos.flush();
            dos.close();
        }
        catch (Exception e) {

            e.printStackTrace();
        }

    }

    public static void set_beep(String mode){


        try {
            FileOutputStream fops = new FileOutputStream("/proc/oem_gpio");
            fops.write(mode.getBytes());
            fops.flush();
            fops.close();

        } catch (FileNotFoundException e) {
            Log.d("err", "found error");
        } catch (IOException e) {
            Log.d("err", "IO error");
        }

    }




    class TimeThread extends Thread {
        @Override
        public void run() {
            do {
                try {

                    Message msg = new Message();
                    msg.what = 1;  //消息(一个整型值)
                    mHandler.sendMessage(msg);// 每隔1秒发送一个msg给mHandler

                    Thread.sleep(1000*3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } while (true);
        }
    }

    //在主线程里面处理消息并更新UI界面
    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:

                    Log.d("auo","ttt=");

                    set_oem_gpio(0x21);
                    try
                    {
                        Thread.currentThread().sleep(100);
                    }
                    catch(Exception e){
                    }
                    set_oem_gpio(0x20);

                    lock_cnt++;


                    String total_cnt="开锁次数"+ Integer.toString(lock_cnt);

                    lock.setText(total_cnt); //更新时间

                    break;
                default:
                    break;

            }
        }
    };

    void lock_ttt(){

        lock_cnt=0;
        new TimeThread().start();
    }


    void img(){

        String cmd;
        cmd="cp /mnt/usb_storage/USB_DISK1/udisk0/uuuu.img /sdcard/uuuu.img";
        try
        {
            final Process process = Runtime.getRuntime().exec(cmd);
            System.out.println("start run cmd=" + cmd);

            //处理InputStream的线程
            new Thread()
            {
                @Override
                public void run()
                {
                    BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
                    String line = null;

                    try
                    {
                        while((line = in.readLine()) != null)
                        {
                            System.out.println("output: " + line);
                        }
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                    finally
                    {
                        try
                        {
                            in.close();
                        }
                        catch (IOException e)
                        {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();

            new Thread()
            {
                @Override
                public void run()
                {
                    BufferedReader err = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                    String line = null;

                    try
                    {
                        while((line = err.readLine()) != null)
                        {
                            System.out.println("err: " + line);
                        }
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                    finally
                    {
                        try
                        {
                            err.close();
                        }
                        catch (IOException e)
                        {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();

            process.waitFor();
            System.out.println("finish run cmd=" + cmd);

            Intent intent=new Intent("android.intent.action.otaupdate");
            intent.putExtra("path","/mnt/internal_sd/uuuu.img");
            //  intent.putExtra("path","/sdcard/Download/update.zip");
            this.sendBroadcast(intent);

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }

    static boolean is_not_free_space = false;	//add by cong, 2010-05-28
    static boolean is_copy_finish = false;				//用来标志是否拷贝完毕的标志
    static boolean is_enable_copy = true;				//是否可以复制的标记，用来强制结束拷贝
    static boolean is_same_path = false;				//标志拷贝时的源路径与目标路径是否一致

    static boolean is_wait_choice_recover = true;	//用来同步是否复盖对话框的标志
    static boolean is_recover = true;				//用来标志是否要复盖已存在文件
    static File mRecoverFile = null;				//当前是否要复盖的文件
    static boolean is_pause_copy = false;
    //static FileControl mFileControl = null;

    private Thread mThread = null;

    static File cope_now_sourceFile = null;
    static File cope_now_targetFile = null;

    static float mhascopyfileLength = 0;
    static float mallcopyfileLength = 0;

    private final int BUFFERE_SIZE = 1024*8;


    private void LOG(String str)
    {
        if(true)
        {
            Log.d(TAG,str);
        }
    }



    int ping_test(String ipString){

        try
        {
            //	Log.i("4g", "ip address" + ipString);

            Process p = Runtime.getRuntime().exec(
                    "ping -c 1 -w 5 " + ipString);
            int status = p.waitFor();
            if (status == 0)
            {
                Log.i("4g", "ping"+ipString+"  ok\n");

                return 0;

            }
            return -1;

        } catch (Exception e)
        {

            return -1;

        }
        //return -1;

    }


}





